package com.lzx.adx.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzs.adx.commmon.service.impl.CrudServiceImpl;
import com.lzx.adx.report.bean.mapper.MeiTuanMapper;
import com.lzx.adx.report.dao.MeituanOrderDao;
import com.lzx.adx.report.dto.MeituanOrderDTO;
import com.lzx.adx.report.entity.MeituanOrderEntity;
import com.lzx.adx.report.service.MeituanOrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;


@Service
public class MeituanOrderServiceImpl extends CrudServiceImpl<MeituanOrderDao, MeituanOrderEntity, MeituanOrderDTO> implements MeituanOrderService {

    @Resource
    private MeiTuanMapper tuanMapper;

    @Override
    public QueryWrapper<MeituanOrderEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        String orderId = (String) params.get("orderId");
        QueryWrapper<MeituanOrderEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(orderId), "order_id", orderId);
        wrapper.eq(null != params.get("handType"), "hand_type", 1);
        wrapper.last(null != params.get("limit"), "limit 1");
        return wrapper;
    }


    @Override
    public void save(MeituanOrderDTO dto) {
        MeituanOrderEntity report=  tuanMapper.toReport(dto);
        this.baseDao.insert(report);
        dto.setId(report.getId());
    }
}